package cn.com.shopec.erp.multiChannel.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;

/**
 * 多渠道订单实体类
 * @author Terry
 *
 */
@Entity
@Table(name = "TBL_CHANNEL_ORDER")
public class ChannelOrder implements java.io.Serializable {
	private static final long serialVersionUID = 1885748953954944192L;
	private String id;						//多渠道订单编号
	private String channelOrderId;			//订单编号
	private String channelOrderType;		//订单渠道 0：京东    1：淘宝  2：天猫  3:自存
	private String orderState;				//订单状态 0：已提交  1：审核通过  2:审核不通过  3:待支付  4:待发货  5:已发货  6:已完成  7:已取消  8:已锁定
	private String deliveryState;			//发货状态 0：未发货  1：已发货
	private String payState;				//支付状态 0：未支付  1：已支付
	private String payType;					//支付方式（1货到付款, 2邮局汇款, 3自提, 4在线支付, 5公司转账, 6银行卡转账）
	private String orderType;				//订单类型（0白拿 1返还）
	private Double orderTotalPrice;			//订单总金额
	private String orderStartTime;			//订单日期
	private String returnOrder;				//售后订单标记 0:不是换货订单 1返修发货,直接赔偿,客服补件 2售后调货
	private String returnState;             //退货状态0:未入库1:已入库2:已换货3:已完成
	private String orderRemark;				//买家下单时订单备注 
	private Set<ChannelOrderItem> orderItems=new HashSet<ChannelOrderItem>();  //订单商品集合
	private ChannelOrderReceiver orderReceiver =new ChannelOrderReceiver();  //订单收货人地址
	private String receiverName;			//收货人名称
	private String receiverPhone;			//收货人电话
	
	public ChannelOrder() {
	}

	public ChannelOrder(String id) {
		this.id = id;
	}

	public ChannelOrder(String channelOrderId, String channelOrderType, String deliveryState, String payState,
			String payType, String orderType, Double orderTotalPrice, String orderStartTime, String returnState) {
		this.channelOrderId = channelOrderId;
		this.channelOrderType = channelOrderType;
		this.deliveryState = deliveryState;
		this.payState = payState;
		this.payType = payType;
		this.orderType = orderType;
		this.orderTotalPrice = orderTotalPrice;
		this.orderStartTime = orderStartTime;
		this.returnState = returnState;
	}

	@OneToMany
	@Cascade(value={CascadeType.SAVE_UPDATE})
	@JoinColumn(name = "channel_order_id",referencedColumnName="channel_order_id")
	@OrderBy(value="itemPrice")
	public Set<ChannelOrderItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<ChannelOrderItem> orderItems) {
		this.orderItems = orderItems;
	}

	@GenericGenerator(name = "generator", strategy = "uuid.hex")
    @GeneratedValue(generator = "generator")
    @Id
    @Column(name = "id", unique = true, nullable = false, length = 32)
    public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
    
	@Column(name = "channel_order_id", length = 30)
	public String getChannelOrderId() {
		return this.channelOrderId;
	}
	
	public void setChannelOrderId(String channelOrderId) {
		this.channelOrderId = channelOrderId;
	}

	@Column(name = "order_state", length = 30)
	public String getOrderState() {
		return orderState;
	}

	public void setOrderState(String orderState) {
		this.orderState = orderState;
	}

	@Column(name = "channel_order_type", length = 30)
	public String getChannelOrderType() {
		return this.channelOrderType;
	}

	public void setChannelOrderType(String channelOrderType) {
		this.channelOrderType = channelOrderType;
	}

	@Column(name = "delivery_state", length = 30)
	public String getDeliveryState() {
		return this.deliveryState;
	}

	public void setDeliveryState(String deliveryState) {
		this.deliveryState = deliveryState;
	}

	@Column(name = "pay_state", length = 30)
	public String getPayState() {
		return this.payState;
	}

	public void setPayState(String payState) {
		this.payState = payState;
	}

	@Column(name = "pay_type", length = 30)
	public String getPayType() {
		return this.payType;
	}

	public void setPayType(String payType) {
		this.payType = payType;
	}

	@Column(name = "order_type", length = 30)
	public String getOrderType() {
		return this.orderType;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	@Column(name = "order_total_price", precision = 30)
	public Double getOrderTotalPrice() {
		return this.orderTotalPrice;
	}

	public void setOrderTotalPrice(Double orderTotalPrice) {
		this.orderTotalPrice = orderTotalPrice;
	}

	@Column(name = "order_start_time", length = 32)
	public String getOrderStartTime() {
		return this.orderStartTime;
	}

	public void setOrderStartTime(String orderStartTime) {
		this.orderStartTime = orderStartTime;
	}

	@Column(name = "return_order", length = 30)
	public String getReturnOrder() {
		return returnOrder;
	}

	public void setReturnOrder(String returnOrder) {
		this.returnOrder = returnOrder;
	}

	@Column(name = "return_state")
	public String getReturnState() {
		return returnState;
	}

	public void setReturnState(String returnState) {
		this.returnState = returnState;
	}

	@Column(name = "order_remark", length = 300)
	public String getOrderRemark() {
		return orderRemark;
	}

	public void setOrderRemark(String orderRemark) {
		this.orderRemark = orderRemark;
	}

	@Column(name = "receiver_name", length = 32)
	public String getReceiverName() {
		return receiverName;
	}

	public void setReceiverName(String receiverName) {
		this.receiverName = receiverName;
	}

	@Column(name = "receiver_phone", length = 32)
	public String getReceiverPhone() {
		return receiverPhone;
	}

	public void setReceiverPhone(String receiverPhone) {
		this.receiverPhone = receiverPhone;
	}

	/*@OneToOne
    @PrimaryKeyJoinColumn*/
	@OneToOne  
	@JoinColumn(name = "id") 
	public ChannelOrderReceiver getOrderReceiver() {
		return orderReceiver;
	}

	public void setOrderReceiver(ChannelOrderReceiver orderReceiver) {
		this.orderReceiver = orderReceiver;
	}
	
}